// router.js
import {
	RouterMount,
	createRouter
} from 'uni-simple-router';

const router = createRouter({
	platform: process.env.VUE_APP_PLATFORM,
	routes: [...ROUTES]
});
//全局路由前置守卫
router.beforeEach((to, from, next) => {
	let uid = uni.getStorageSync('uid')
	if (!uid) {
		if (to.path == '/pages/cart/cart') {
			next({
				path: '/pages/public/login',
				params: {
					msg: '我拦截了cart并重定向到了路由login页面上',
				},
				NAVTYPE: 'push'
			})
		}
	}
	if (!uid) {
		if (to.path == '/pages/user/user') {
			next({
				path: '/pages/public/login',
				params: {
					msg: '我拦截了user并重定向到了路由login页面上',
				},
				NAVTYPE: 'push'
			})
		}
	}
	next();
});

// 全局路由后置守卫
router.afterEach((to, from) => {
	console.log('跳转结束')
})

export {
	router,
	RouterMount
}
